	 					
package com.module.device.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import base.dao.GenericHibernateDao;
import base.util.Page;
import com.module.device.vo.DeviceActiveStatus;

public class DeviceActiveStatusDao  extends GenericHibernateDao<DeviceActiveStatus, Long> {	
	private DeviceActiveStatusDao(){}
	
	private static DeviceActiveStatusDao dao;
	
	public synchronized static DeviceActiveStatusDao getInstance(){
		if(dao==null)
			dao = new DeviceActiveStatusDao();
		return dao;
	}
	/**
	 * 查询列表
	 * @param session
	 * @param bean
	 * @param start
	 * @param limit
	 * @return
	 * @throws SQLException
	 */
	public Page getList(Session session,DeviceActiveStatus bean,Integer start, Integer limit)throws SQLException{
		Page page = new Page();
		StringBuffer sb = new StringBuffer();
	    StringBuffer condition = new StringBuffer();
		List<Object> params = new ArrayList<Object>();
		
																											
	
		sb.append("from DeviceActiveStatus as obj where 1=1 ");
		sb.append(condition);
	//	sb.append(" order by status asc,type desc,createTime desc ");
	
		Query query = session.createQuery(sb.toString());
	        int i = 0;
			for (Object obj : params) {
				query.setParameter(i, obj);
				i++;
			}
		query.setFirstResult(start).setMaxResults(limit);
		
		Query totalQuery = session
		.createQuery("select count(*) from DeviceActiveStatus as obj where 1=1 "+condition);
		int j = 0;
		for (Object obj : params) {
			totalQuery.setParameter(j, obj);
			j++;
		}
		page.setTotal((long) ((Long) totalQuery.uniqueResult()).intValue());

		
		page.setRows(query.list());	
		return page;
	}
	
	
	/**
	 * 查询列表
	 * @param session
	 * @param bean
	 * @param start
	 * @param limit
	 * @return
	 * @throws SQLException
	 */
	public List findeBySoftwareCode(Session session,String softwarecode)throws SQLException{
		Page page = new Page();
		StringBuffer sb = new StringBuffer();
		sb.append("from DeviceActiveStatus as obj where 1=1 and obj.softwareCode='"+softwarecode+"'");
		Query query = session.createQuery(sb.toString());
		return query.list();
	}
	
	
	
	
	
}

